package com.codeZ.ObserverPattern.instance;

import java.util.ArrayList;
import java.util.List;

/**
 * 开奖服务
 *
 * @author codeZhang
 * @Date 2024/8/26 11:09
 */
public abstract class LotteryService {

    private final EventManager eventManager;

    public LotteryService(){
        List<Enum<EventManager.EventType>> arrayList = new ArrayList<>();
        arrayList.add(EventManager.EventType.Message);
        arrayList.add(EventManager.EventType.MQ);
        //设置事件类型
        eventManager = new EventManager(arrayList);
        //订阅
        eventManager.subscribe(EventManager.EventType.Message,new MessageEventListenerObserver());
        eventManager.subscribe(EventManager.EventType.MQ,new MQEventListenerObserver());
    }

    public LotteryResult lotteryAndMsg(String uId){
        LotteryResult result = lottery(uId);
        //发送通知
        eventManager.notify(EventManager.EventType.Message,result);
        eventManager.notify(EventManager.EventType.MQ,result);
        return result;
    }


    public abstract LotteryResult lottery(String uId);

}
